The defect feature extraction of ultrasonic phased array detection based on adaptive region growth

An ultrasonic phased array defect extraction method based on adaptive region growth is proposed, aiming at problems such as difficulty in defect identification and extraction caused by noise interference and complex structure of the detected object during ultrasonic phased array detection. First, bilateral filtering and grayscale processing techniques are employed for the purpose of noise reduction and initial data processing. Following this, the maximum sound pressure within the designated focusing region serves as the seed point. An adaptive region iteration method is subsequently employed to execute automatic threshold capture and region growth. In addition, mathematical morphology is applied to extract the processed defect features. In the final stage, two sets of B-scan images depicting hole defects of varying sizes are utilized for experimental validation of the proposed algorithm’s effectiveness and applicability. The defect features extracted through this algorithm are then compared and analyzed alongside the histogram threshold method, Otsu method, K-means clustering algorithm, and a modified iterative method. The results reveal that the margin of error between the measured results and the actual defect sizes is less than 13%, representing a significant enhancement in the precision of defect feature extraction. Consequently, this method establishes a dependable foundation of data for subsequent tasks, such as defect localization and quantitative and qualitative analysis.


Introduction
Ultrasonic phased array technology, a prominent tool in industrial non-destructive testing, is extensively employed for detecting and imaging internal defects such as cracks, holes, and other anomalies in components.B-type detection is predominantly utilized in this context [1].This technique surpasses traditional A-type detection by displaying multiple A-type waveform data on a single image.Moreover, A-wave data can be transformed into RGB images through data processing, aiding inspectors in deducing defect location and size [2][3][4].Nevertheless, Bscan images from ultrasonic phased arrays often contain considerable noise due to factors like environmental noise, component geometry, and detection equipment.This noise image is marked by eight-connectivity discrimination methods for defect and contour tracking through image preprocessing, bilateral filtering, automatic region growth, mathematical morphological processing, etc. Geometric features such as perimeter, area, perimeter-area ratio, and long and short axes are selected to quantify and evaluate the accuracy of different methods for extracting defect features through numerical results and statistics.Fig 1 shows the specific process.

The dataset
The ultrasonic phased array device is connected to MATLAB via USB, and the detecting device collects data from the B-type ultrasonic phased array test block and saves them as text documents, which are uploaded to the software in real time.The text document is converted into a numerical matrix of 128 × 400 in uint8 format by program calculation.The RGB value is assigned to the matrix value, the color is filled using the pcolor function, and the final detection image is formed by interpolation.The number of pixels in the image is 51200, and by identifying the number of pixels in the target area, the real value of each feature can be obtained according to scale conversion.

Data processing
The images were only reformatted and normalized.Then, the path to the invoked image data was set, and the proposed algorithm was generally designed to work on the raw data; therefore, no further preprocessing was performed on the images.The raw data of the image and the processing code are already visible on GitHub (github.com/Sonyk700/code) and shown in the S1 File.

Image preprocessing
The defect image obtained by the ultrasonic phased array detection system is a color image.However, the algorithm for color images is complex and inefficient during actual processing.Grayscale processing is needed to separate single-channel images to facilitate the extraction of defect characteristics.The grayscale image shows the depth of color.Its grayscale value is 0 to 255.0 is black and 255 is white, and higher values are brighter.Grayscale is the projection on three channels of color image R (Red), G (Green), and B (Blue).As shown in Eq 1, the specific gray value can be obtained using the weighted average method [12].

Bilateral filtering
To better segment the target region of subsequent ultrasonic images and extract the target region of ultrasonic images for feature analysis, the ultrasonic images require preprocessing, such as filtering and denoising, before ultrasonic image segmentation.Bilateral filtering removes noise and preserves edges, and it is a nonlinear filtering algorithm with a dual filtering function [13].Bilateral filtering is a filtering function containing two Gaussian bases; thus, it not only considers the geometric proximity of each pixel value in the image but also considers the similarity of each pixel value in terms of brightness.The smooth image is obtained by adaptive filtering through the nonlinear combination of the two.The core idea of bilateral filtering is to multiply the Gaussian function related to the spatial distance (the Euclidean distance between the current point and the center point) with the Gaussian function related to the pixel distance (the absolute value of the difference between the pixel value of the current point and the center point).The principle expression of bilateral filtering is given in Formula 2.
where σ d is the standard deviation in the spatial domain, σ r is the standard deviation of the value range, (i, j) is the position of the current pixel point, (k, l) is the position of the central pixel point, I(i, j) is the pixel value of the current point, and I(k, l) is the pixel value of the central point.Thus, the mathematical form of the spatial domain Gaussian function is given as follows: Eq 4 is the mathematical form of the range Gaussian function.
Spatial filtering convolves only the weight coefficient of the spatial distance (the closer to the center point, the larger the weight coefficient) with the image to determine the pixel value of the center point.Range filtering implies that the point whose pixel value is closer to that of the center point has a larger weight and that the point whose pixel value differs greatly possesses a smaller weight coefficient in the neighborhood.The range weight is determined by the Gaussian function range.Therefore, σ d and σ r directly affect the denoising ability of the filter.The larger the value of σ d is, the greater the effect on each pixel, and the image will become more blurred.σ d should be larger when there are fewer noise points.The larger σ r is, the more obvious the blurring effect.

Adaptive region growing algorithm
Image segmentation includes the technology and process of dividing an image into several nonoverlapping, meaningful, and identical feature areas to extract the target of interest.The features here could include the grayscale, color, texture, etc. Predefined targets could correspond to a single area or multiple areas [14].
The defects of ultrasonic phased array B-scan images are usually connected regions having similar features, such that the region growing method can be used to segment the images.The basic idea of traditional region growth is to find a seed point pixel for each region that needs to be split as the starting point for growth.Thus, pixels possessing the same or similar properties as the seed pixel in the neighborhood around the seed pixel (based on some predefined criteria for growth or similarity) are merged into the region where the seed pixel points are located.These pixels are used as new seed pixels to continue the above process until no more pixels that meet the conditions are included, after which a region is finally formed [15].
As shown in Fig 2, a schematic model of region growth in ultrasound images is established to better understand the basic theory of automatic region growth.The parameters and meanings of each variable are listed in Table 1 to easily distinguish between parameters.
As shown in Fig 2, there is an image matrix with 4 × 5 pixels and a grayscale of 1. Whether each pixel is black or white is used as a measure of its similarity.The steps of implementation of the region-growing method are as follows: 1. First, the starting seed point is set.The starting seed point is a point (m 0 , n 0 ) in Fig 2(a Therefore, three problems need to be solved during the actual application of the regiongrowing method.The first is to determine a set of seed pixels (selecting seeds) that could correctly represent the desired region, the second is to determine the criteria for including adjacent pixels in the growth process (determination threshold), and the third is to confirm the conditions or rules for stopping the growth process (stopping conditions).

Mathematical morphology processing method
Due to the geometric shape and coupling status of the complex components, problems such as divergence and false boundaries in the defects after segmentation persist, and thus, defect extraction and quantization accuracy are seriously affected.Therefore, an erosion algorithm is used for further optimization of the image after binarization [16].
The structuring element is selected as a 3 × 3 black point, and the erosion algorithm reduces the boundary of the object by one pixel along the perimeter.Edge detection is equivalent to corroding the original image with 9 points structuring elements of 3 × 3 blocks and then the original image minus the eroded image [17].
T is the image, and B is the structuring element.B z represents the result after structural element B shifts to Z, B s represents the symmetric set of structural elements to the point of origin, and the mathematical expression is as follows: Table 1.Definition of variables in the model.

No. Variable names
Variable definition The coordinates in the depth direction The coordinates in the moving direction of the ultrasonic transducer The gray value at the point (m 0 , n 0 )  Then, the erosion operation is defined as: The boundary operator extracted by mathematical morphology is: where E is 3 × 3 structural elements and ED (T) represents the boundary of image T.
The edge width of the object detected by this method is only one pixel; therefore, it has high positioning accuracy.The binarized image has complete object outlines; thus, the extracted edges are continuous.

Algorithm implementation
The implementation of the improved adaptive region growing algorithm plays a pivotal role in effectively segmenting connected regions sharing characteristics with the seed growth point, thereby providing precise regional boundary information.Fig 3 presents the physical setup of the experimental device.Utilizing the CTS-602 device, ultrasonic phased array B-scan imaging is conducted on the defect area of an oblique through-hole in the phased array B-shaped test block.The detection depth at hole #1 is set at 20 mm, where the optimal echo amplitude is achieved when the focusing area of the ultrasonic phased array coincides with the detection site.Consequently, a focusing depth of 20 mm is selected to maximize detection capability.The choice of transducer hinges on its focusing proficiency.The TL5F64 transducer with a dynamically adjustable near-field depth ranging from 28.63 mm to 83.3 mm is chosen.Prior research indicates that the best detection results are obtained near the near-far field boundary [18].Hence, a near-field depth of 28.63 mm is selected, corresponding to a transducer aperture of 20 mm.To balance aspects like acoustic attenuation, focusing performance, and transducer resolution, a center frequency of 5 MHz is chosen for the transducer.Despite processing, serious noise interference persists in the grayscaled image.Bilateral filtering is employed to enhance the signal-to-noise ratio and filter out noise.In this process, a larger standard deviation in calculations leads to a smaller weight difference, implying less emphasis on this factor.Conversely, σ d indicating spatial domain smoothness, is crucial for areas lacking sharp edges or exhibiting gradual transitions.An increase in σ d helps eliminate noise in these regions.However, if σ d exceeds 1, the image's detail processing capability starts to diminish, thus σ d is set at 1.σ r relates to the range of value differences, where reducing σ r accentuates edge definition, resulting in a clearer image.Utilizing Laplace for fast standard deviation estimation, optimal results are achieved with σ r set at 0.1 [19].The local intensity sliding window is typically not more than 11 × 11 pixels and is always an odd number.In this study, it is uniformly set to 11 × 11 to boost smoothness and computational efficiency.Care is taken in selecting the filter half-width N, as a larger value can over-smooth edges and target regions, hindering gradient vector detection.Consequently, N is finalized at 5, based on the sliding window size.The detailed information of the image can not only be preserved but can also achieve a good filtering effect after adopting bilateral filtering.Due to the defect image in the processed ultrasonic phased array B-scan image, it does not connect with other areas.The region growing method is used for feature image segmentation to effectively segment the connected regions with the same features as defect points and provide good region boundary information.
The most critical aspect of the adaptive region growing algorithm is to determine the growth starting point of the growth criteria.The reflected signals of defects generally appear as prominent color values in ultrasonic phased array B-scan images.For example, aiming at a 256-level grayscale image, the higher the amplitude of the defect signal is, the brighter the color.Therefore, while determining the defect region, the prominent color on the B-scan image must first be traversed, which is equivalent to the seed pixel in the region growth method, and then the defect signal region from the inside and outside should be determined.
The position of the scan line was adjusted such that it lies in the center of the defect, and the A-wave detection data at the scan line in the ultrasonic phased array B-scan image were extracted.As shown in Fig 7, the defect signal is reflected in the form of peaks.Usually, the pixel with a prominent color value in the ultrasonic B-scan image is selected as the seed pixel, which is at the maximum amplitude.Since the amplitude of the initial wave is higher than the  The seed point is compared with its 8 neighborhood pixels (vertical, horizontal, and 2 diagonal) by using a 3 × 3 sliding window G.The average pixel value of the window corresponding to each point is calculated in the region of interest as follows: where f(i,j) is the pixel point in the region of interest; f(x,y) is the pixel point in the window; N is the sliding window size; I is the image window area, and the threshold is set as T m .Thus: where C is a constant coefficient, and C is set to 2 by consulting references [20] in this paper; K is taken as 9, which is the total number of pixels in the region of interest I.The growth conditions were determined from the regional growth of the initial seed point.The gray value is one of the main features used to distinguish the target from the background in ultrasound phased array B-scan images.The absolute value of the gray value difference (D = |f 1 -f 2 |) between two adjacent pixels is used as the similarity criterion.The threshold T is set, and the pixels in the neighborhood around the seed point are searched.If D�T, the point must be grown, and it should be used as a seed point to continue to grow.Among them, the threshold T m is kept dynamically updated during the sliding process of window G. Next, the average gray value of the area where the new pixel is located is compared with the gray value of the pixels in each area, and growth is stopped until it reaches the boundary or the points that no longer meet the conditions.The error caused by the transition and merging growth of different regions in the region where the gray level changes slowly is overcome by adopting this method.Fig 9 shows the algorithm pseudocode.
A suitable initial threshold must be set before the growth of ultrasound phased array B-scan images, as it will result in execution failure of the algorithm if the threshold is chosen to be too large or too small.Studies have shown that selecting the average gray value of the B-scan image after preprocessing as the initial threshold T could obtain a better segmentation effect.The average grayscale value of the target image can be calculated from the original data to be 35.Therefore, T is selected as 35.Table 2 compiles all the parameters involved in the image processing procedure.The specific algorithm process is as follows.
1.A 3 × 3 sliding window is used to traverse the ultrasound B-scan image.The average value of the window grayscale is calculated, and the point with the largest amplitude of the focal length position is selected as the initial seed point.
2. The unmarked pixels in the surrounding 8 neighborhoods are searched sequentially, starting from the seed point.It needs to be judged whether it is a boundary point and if it satisfies the growth condition D�T.If it meets the growth conditions and is not a boundary point, the pixel is marked.
3. The seed points are continuously updated, the marked points are regarded as new seed points, the average gray value of the window is recalculated as the updated window threshold T m , new pixel points are obtained, and the average gray value of the area where the new pixel is located is compared with each grayscale value of the domain pixels.If the seed points have been increased, return to step 2; if not, proceed with the next step.It is necessary to erode and dilate the image post-binarization to extract defect features more accurately.Erosion and dilation are two basic morphological operations that implement the resulting elements in an input image and generate a corresponding output image.The dilation operation convolves the input image with some kernels.The maximum pixel value overlapped by the kernels is calculated and used for replacing the image pixels at the anchor points during the scanning of kernels on the image.The entire operation will expand the highlighted  area in the image, and the image dilation operation process follows the following formula: The process of the erosion operation calculates local minima in the kernel region.The minimum pixel value of kernel overlap is calculated while scanning the kernel, and this value is used to replace the image pixel of the anchor point.
The closed operation is used for filling the small holes in the target, connecting the disconnected adjacent targets, and smoothing the edges without significantly changing the area.

Experimental analysis
The proposed method will be compared with the current effective defect feature extraction algorithm of ultrasonic phased array B-scan images to verify the effectiveness of the proposed method.The histogram threshold method [6], the Otsu-AWDO method [5], the K-means clustering algorithm [7], and the modified iterative method [9] are used to process the detection image of hole #1 and defect #2 to obtain the optimal defect extraction method of the ultrasonic phased array B-scan image more accurately.The results are shown in Figs 11 and 12, respectively.
The noise and clutter in all final images have been basically filtered out according to the analysis of the #1 and #2 detection images processed by different methods.The final image is clear, and the shape of the target image is complete, which is beneficial to the subsequent feature extraction.However, it can be seen from Fig 11 that the target image processed by the histogram threshold method has slender gullies and incomplete contour lines, while the target  3. Thus, the relative error δ can be obtained according to formula 12.
where Δ is the absolute error and L is the real value.Table 3 reveals the dimensions of defects #1 and #2 as determined by the algorithm.The major axes measure 1.60 mm and 2.12 mm, while the minor axes are 1.63 mm and 2.17 mm, respectively.These values exhibit a slight overestimation compared to the actual defect size of 1.5 mm.The algorithm calculates the areas of these defects as 1.98 mm 2 and 3.65 mm 2 , respectively, indicating minor deviations from the true sizes.Figs 11 and 12 demonstrate that the algorithm successfully retains the detailed contours of the defects, ensuring well-defined boundaries and accurately representing their fundamental shapes and sizes during the eigenvalue extraction process.
The improved Otsu method demonstrates enhanced accuracy in extracting defect areas, with area errors of 12.8% and 15.6% for defects #1 and #2, respectively.However, this method yields unclear defect boundaries, leading to significant errors in contour circumference.Iterative methods, used for extracting basic features of small defects, provide relatively complete boundary information.The extracted perimeter-to-area ratio for defect #1 is 2.55 (compared to the actual value of 2.67), but the relative error in feature extraction for larger defects (approximately 2 mm in diameter) is notably higher, reaching 1.73 (against the actual value of 2).The k-means clustering algorithm shows better performance for larger defects, while the histogram threshold method is less accurate for defect detection.The feature error for each defect is considerable using these methods, and the contour often undergoes significant deformation, which is not conducive to quantitative and qualitative defect analysis.
A comprehensive analysis indicates that the relative errors in defect areas and perimeter-toarea ratios extracted by the adaptive region growth method are below 13% and 6%, respectively, with the relative error of major and minor axes under 9%.The relative errors of all defect quantitative eigenvalues extracted by this algorithm are lower than those obtained using the histogram threshold method, Otsu-AWDO method, K-means clustering algorithm, and modified iterative method.The detection image processed by the proposed algorithm and the extracted defect feature values accurately reflect the actual size and shape of defects, allowing for more precise defect extraction and quantification.

Study limitations
The use of bilateral filtering for noise reduction in the initial phase is particularly effective in middle and low-frequency domains, preserving crucial contour details in the target image.However, in high-attenuation materials or heterogeneous media, where ultrasonic phased array techniques require increased transmission frequency for improved sound wave penetration, bilateral filtering may struggle to fully eliminate high-frequency noise.This could result in undesired artifacts in the resultant image.To address this issue, more advanced techniques, such as New Reverse Time Migration [22], must be employed in conjunction with bilateral filtering.Additionally, it is worth noting that the lattice Boltzmann method offers a valuable approach for optimizing transducer parameters and enhancing the overall quality of ultrasonic phased array imaging [23].

Conclusion
Ultrasonic phased array B-scan images differ significantly from traditional ultrasonic detection images, particularly in terms of gray level differentiation and the overlapping of the initial wave, defect echo, bottom echo, and noise.Traditional image segmentation methods like the histogram threshold, Otsu method, K-means clustering algorithm, and modified iteration method face challenges in these contexts due to poor filtering effects, fuzzy detail processing, and unclear boundary recognition, leading to inaccuracies in defect feature extraction.In this study, the noise-mixed ultrasonic phased array B-scan image is first converted to grayscale, followed by bilateral filtering to retain image details while filtering noise.The scanning line position is adjusted in real-time, and the A-wave data of the defect scanning line are extracted to set regional growth seed points automatically.The 3 × 3 moving window technique is employed for traversing all areas, continuously updating seed points and window thresholds for accurate defect image segmentation.Finally, the combination of closed operation and Sobel operator, based on mathematical morphology, is used for defect edge and feature extraction.The results demonstrate the algorithm's superiority in segmenting and extracting ultrasonic phased array B-scan images of defects such as holes.
The segmented and extracted ultrasonic B-scan defect images exhibit distinct edges and accurate features, laying a solid foundation for subsequent identification and analysis of acoustic defects.Future work will focus on improving device instrumentation for more precise evaluation of tumors and lesions in medical ultrasound, aiding in diagnosis and prognosis of circulatory system tumors and lesions, and enabling detection and analysis of surface and internal defects in composite materials and special equipment using machine vision technology.

); 2 .
The seed point characteristics are compared with the characteristics of the unclassified pixels in the neighborhood.If the characteristics are similar, they are merged into the same region to form a new seed point.In Fig 2(b), the pixel characteristics of point (m 0 , n 0 ) and its 8 neighbor points are compared.If the colors are the same (both black), they will be merged into the same area as a new seed point; 3. Step (2) is repeated for new seed points until no new seed points can be merged into the region, and finally, Fig 2(c) is obtained.The ultrasonic B-scan image matrix T(m, n) is divided into two parts: non-seed region U and seed region S e .

Fig 2 .
Fig 2. Schematic diagram of region growth in the B-scan image.https://doi.org/10.1371/journal.pone.0297206.g002 Fig 4 illustrates the Phased array B-type test block along with the original detection image.The original detection image is comprised of the background, target, and noise clutter.The presence of redundant information, such as noise and clutter, impedes defect detection.

4 .
The marked points are separated from the image and segmented, and the binarized image after segmentation is shown in Fig 10(a).

Fig 10 .
Fig 10.Mathematical morphological processing.(a) The binarized image after segmentation; (b) The image after the closed operation; (c) The image marked by the Sobel operator.https://doi.org/10.1371/journal.pone.0297206.g010 Fig  10(b)  shows an image processed by the closed operation.The Sobel operator is used for edge extraction to facilitate the subsequent extraction of area, perimeter, and other features; it can produce a better detection effect, smooth the noise, and provide more accurate edge direction information[21].Fig 10(c)  shows the corresponding results.